#ifndef _VN_SFML_2D_RENDER_ENGINE_H_
#define _VN_SFML_2D_RENDER_ENGINE_H_

#include "RenderEngine.h"
#include <map>
#include "..\Managers\SFMLTextureManager.h"
#include "..\Graphics\SFMLSprite.h"
#include "..\Generic\IniFile.h"
#include "..\Graphics\SFMLCamera.h"
#include "..\Debug\DebugDraw.h"

class DebugDraw;
class SFMLSpriteManager;
class SFML2DRenderEngine : public RenderEngine
{
public:
	
	enum RenderState
	{
		RENDER_STATE_WINDOW = 0,
		RENDER_STATE_TEXTURE
	};

	SFML2DRenderEngine(unsigned int);
	virtual ~SFML2DRenderEngine(void);

	virtual void initialize();

	virtual void beginRender();
	virtual void render();
	virtual void endRender();

	virtual void pollEvents();

	virtual vn::Sprite* createSprite(unsigned int, const std::string&, float = 0.0f);
	virtual vn::Text* createText(unsigned int p_view, const std::string& p_fontID, const std::string& p_string, float p_layer = 0.0f);
	virtual vn::TileEngine* createTiles(unsigned int, const std::string&, float = 0.0f);
	virtual vn::Camera* createCamera(unsigned int, const std::string& p_cameraID);	// create a camera on a specific view and set camera ID
	virtual vn::Camera* getCamera(const std::string& p_cameraID);
	virtual vn::RectangleShape* createRectangleShape(unsigned int p_view, const vn::Vector2& size, float p_layer = 0.0f);
	virtual void destroySprite(vn::Sprite*);
	virtual void destroyText(vn::Text*);
	virtual void destroyCamera(vn::Camera*);
	virtual void destroyTileEngine(vn::TileEngine*);
	virtual void destroyRectangleShape(vn::RectangleShape*);
	virtual void destroyAllDrawables();
	virtual void clearAll();
	virtual void setView(unsigned int);

	SFMLSpriteManager& getSpriteManager() { return *m_spriteManager; }

private:
	void recreateIniFile(IniFile&);
	void testVideoMode(sf::VideoMode&);
	inline void clearCameras();

	int m_currentRenderState;
	bool m_isInitialized;

	sf::RenderWindow m_window;
	sf::RenderTexture m_renderTexture;

	SFMLSpriteManager* m_spriteManager;
	std::map<std::string, vn::SFMLCamera*> m_cameras;
	DebugDraw* m_debugDraw;
};

#endif // _VN_SFML_2D_RENDER_ENGINE_H_